-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEXT-11081 - Improve performance of RepositoryIterator and remove a possible next request #3602
base: trunk
Are you sure you want to change the base?
Conversation
src/Core/Framework/Test/DataAbstractionLayer/Dbal/RepositoryIteratorTest.php
Outdated
Show resolved
Hide resolved
src/Core/Framework/Test/DataAbstractionLayer/Dbal/RepositoryIteratorTest.php
Show resolved
Hide resolved
src/Core/Framework/Test/DataAbstractionLayer/Dbal/RepositoryIteratorTest.php
Show resolved
Hide resolved
@@ -56,6 +58,23 @@ public function __construct( | |||
$this->context = clone $context; | |||
} | |||
|
|||
public function reset(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe name it rewind
? https://www.php.net/manual/en/function.rewind.php That's what php use for such things.
A simple php doc would also be nice:
Rewinds the Iterator to the beginning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I start calling it rewind, others would expect other iterator methods, right? I mean I can rename it but I assume, that this is creating confusion
@@ -71,19 +90,29 @@ public function getTotal(): int | |||
*/ | |||
public function fetchIds(): ?array | |||
{ | |||
if ($this->endReached) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
$repositoryIterator->loop(function(array $entities) {
});
$repositoryIterator->loopIds(function(array $ids) {
});
In this case we don't have to leak all of this internal "rewind" etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thought. How would one break this loop? Return false? In my suggestions of the getIterator implementation you have the option to just not continue using the iterator. But I like the closure approach. Feels not very php though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add some generators as we once written about. This allows for easier flow control by using language features.
…d remove a possible next request
0. Context
This is a follow-up pull request to #1311 . The reasoning did not change but I rebased, add a test and moved the change from the CartRuleLoader into the RuleLoader as this has been moved.
1. Why is this change necessary?
The RuleLoader already makes this educated guess that there won't be a next result when the current iteration doesn't fill the required criteria limit. Why don't do this in general?
2. What does this change do, exactly?
Add an other state to the already stateful RepositoryIterator that knows when to stop.
During test writing I noticed, that path coverage needs a different entity definition, that is iterated differently. But to reset an iterator you need to know how to reset the criteria. So I added a reset method as well.
3. Describe each step to reproduce the issue or behaviour.
4. Please link to the relevant issues (if any).
https://issues.shopware.com/issues/NEXT-11081
5. Checklist